package cn.yeziji.forum.bo.chatroom;

import cn.yeziji.forum.common.Msg;
import cn.yeziji.forum.common.websocket.Chatroom;
import lombok.Data;

/**
 * 聊天一对一信息数据传输对象
 *
 * @author gzkemays
 * @since 2022/4/1 10:11
 */
@Data
public class ChatPrivateMsgBO extends Msg {
  /** 接受信息者的头像 */
  String toAvatar;
  /** 发送者的头像 */
  String fromAvatar;
  /** 是否属于直接对线聊天 */
  Boolean toView;
  /** 如果用户在线，那么这个数值为用户的 token */
  String toOnlineKey;

  public ChatPrivateMsgBO buildByChatroom(Chatroom chatRoom) {
    if (to == null) {
      to = chatRoom.getTo();
    }
    if (from == null) {
      from = chatRoom.getFrom();
    }
    if (chatroom == null) {
      chatroom = chatRoom.getChatroom();
    }
    if (key == null) {
      key = chatRoom.getKey();
    }
    toView = chatRoom.getUpdateTime() != null;
    msg = chatRoom.getMsg();
    timestamp = System.currentTimeMillis();
    return this;
  }
}
